package com.cnvai.cms.web.utils;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hlc.javautils.TextEncryptUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.security.authentication.encoding.PasswordEncoder;

import com.cnvai.cms.business.impl.AccountServiceImpl;

public class CMSEncoder implements PasswordEncoder {
	private static final Log log = LogFactory.getLog(AccountServiceImpl.class);

	public String encodePassword(String password, Object arg1) throws DataAccessException {
		try {
			password = TextEncryptUtils.encrypt(password);
		} catch (Exception e) {
			log.info(e);
		}
		return password;
	}

	public boolean isPasswordValid(String password, String usrpass, Object arg2) throws DataAccessException {
		boolean result = false;
		try {
			result = TextEncryptUtils.matching(password, usrpass);
		} catch (Exception e) {
			log.info(e);
		}
		return result;
	}

}
